﻿using Core;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

[CreateAssetMenu(menuName = "Mini/Sys/Conf/Game")]
public class TblGame : AbstractSOTable<int, TblGame.Conf>, IEnumTable
{
    [Serializable]
    public class Conf : ITableConf<int>
    {
        public int Index => Id;

        public int Id;

        public string Name;

// #if UNITY_EDITOR
        public string Desc;

// #endif
        public ESceneOrientation Orientation;

        [Range(5, 60)]
        public int FrameRate = 30;

        //public bool SingleMode;
        // public bool ShowMenubar;

        // public GameObject CameraDriver;
        
        public void Awake() { }
    }

    public List<(int, string)> GetEnumList()
    {
        var list = new List<(int, string)>();
        foreach (var conf in Confs)
        {
            list.Add((conf.Id, conf.Name));
        }

        return list;
    }

    public Conf Find(string gameName)
    {
        for (var i = 0; i < Confs.Length; i++)
        {
            var conf = Confs[i];
            if (conf.Name == gameName)
            {
                return conf;
            }
        }

        return null;
    }

    public int IndexOf(string gameName)
    {
        for (var i = 0; i < Confs.Length; i++)
        {
            var conf = Confs[i];
            if (conf.Name == gameName)
            {
                return i;
            }
        }

        return -1;
    }

    public int IndexOf(Conf c)
    {
        for (int i = 0; i < Confs.Length; i++)
        {
            var conf = Confs[i];
            if (conf == c)
            {
                return i;
            }
        }

        return -1;
    }

    public void Print()
    {
        foreach (var conf in Confs)
        {
            Debug.Log(conf.Name);
        }
    }
}